package com.jp.fm.service;

import java.util.ArrayList;
import java.util.List;

import com.jp.fm.dao.CategoryDao;
import com.jp.fm.dao.TransactionDao;
import com.jp.fm.data.Account;
import com.jp.fm.data.Transaction;

public class AccountService {

	private TransactionDao transactionDao = null;
	private CategoryDao categoryDao = null;

	public List<Account> removeHiddenAccounts(final List<Account> accounts) {

		List<Account> accountListRet = new ArrayList<Account>(accounts);

		for (Account account : accounts) {
			if (account.isHidden()) {
				accountListRet.remove(account);
			}
		}

		return accountListRet;
	}

	public List<Transaction> getAccountFees(final Account account) {

		List<Transaction> fees = transactionDao.findByAny(
				categoryDao.findByName("Fees"), null, null, account.getName(),
				null, null);

		return fees;
	}

	public List<Transaction> getAccountRewards(final Account account) {

		List<Transaction> rewards = transactionDao.findByAny(
				categoryDao.findByName("Rewards"), null, null,
				account.getName(), null, null);

		return rewards;
	}

	public final void setTransactionDao(final TransactionDao transactionDao) {
		this.transactionDao = transactionDao;
	}

	public final void setCategoryDao(final CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}
}